﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.RoleMenuCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.RoleMenuHandler
{
    /// <summary>
    /// 查询角色命令处理类
    /// </summary>
    public class QueryRoleHandler : IRequestHandler<QueryRoleCommand, APIResult<List<Role>>>
    {
        /// <summary>
        /// 角色仓储接口
        /// </summary>
        private readonly IBaseRepository<Role> roleRep;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleRep">角色仓储接口</param>
        public QueryRoleHandler(IBaseRepository<Role> roleRep)
        {
            this.roleRep = roleRep;
        }

        /// <summary>
        /// 方法
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>任务</returns>
        public Task<APIResult<List<Role>>> Handle(QueryRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            var list= roleRep.GetAll();
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";
            result.Data=list.ToList();
            return Task.FromResult(result);
        }
    }
}
